Skip to content

Conversation

@night1rider
Copy link
Contributor

@night1rider night1rider commented Dec 11, 2025

Fix CMAC heap pointer reference in wc_CmacFree() and wc_CMAC_Grow()

Issue

The wc_CmacFree() function was attempting to access cmac->heap which does not exist in the Cmac structure, thus causing a compile failure. Additionally, wc_CMAC_Grow() was passing NULL for the heap parameter, creating an pointer mismatch if the heap is non NULL. The Cmac structure contains an Aes member, and it is the Aes structure that has the heap field.

How to Reproduce

./autogen.sh
./configure --enable-cmac CFLAGS="-DWOLFSSL_HASH_KEEP"
make

Context: How heap is initialized

In wc_InitCmac_ex() (line 149: cmac.c), the heap parameter is passed to wc_AesInit():

ret = wc_AesInit(&cmac->aes, heap, devId);

This stores the heap pointer in cmac->aes.heap. So when allocating/freeing CMAC memory, we should use cmac->aes.heap to ensure we're using the same heap pointer throughout the CMAC lifecycle.

Fix

Two changes in wolfcrypt/src/cmac.c:

  1. Line 74 - wc_CMAC_Grow(): Changed NULL to cmac->aes.heap when calling _wc_Hash_Grow() to ensure allocation uses the correct heap
  2. Line 260 - wc_CmacFree(): Changed cmac->heap to cmac->aes.heap to use the correct heap pointer for deallocation

@night1rider night1rider self-assigned this Dec 11, 2025
@night1rider night1rider force-pushed the CMAC-Compile-Issue branch 2 times, most recently from c76f8c3 to bdc2cfc Compare December 11, 2025 22:00
@night1rider
Copy link
Contributor Author

night1rider commented Dec 12, 2025

jenkins retest this please: jenkins error with PRB-generic-config-parser/PRB-dtls.txt_9

@night1rider
Copy link
Contributor Author

jenkins retest this please

@SparkiDev SparkiDev merged commit 19cba1c into wolfSSL:master Dec 14, 2025
369 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants